<?php

namespace Admin\Model;

use Think\Model;

class SysUserModel extends Model {
    // 自动验证
    protected $_validate=array(
        array('userName','require','用户名必须',0,'',3), // 验证字段必填
    );

    public function addData($data){
        $date['userName']=$data['userName'];
        if (!$data['userName']) {
            return ['status'=>false,'info'=>'请填写用户名'];
        }
        $data['state']='ON';
        $result=$this->add($data);
        if ($result) {
            return ['status'=>$result,'info'=>'添加成功'];
        }else{
            return ['status'=>$result,'info'=>'添加失败'];
        }
    }
    public static function newSelf()
    {
        return new self();
    }
    public function findByUserName($username)
    {
        $where['state']='ON';
		$where['userName']=$username;
		return $this->where($where)->find();
    }
    public function findById($id)
    {
        $where['state']='ON';
		$where['userID']=$id;
		return $this->where($where)->find();
    }
    public function verificationPassWord($input_pass,$pass)
    {
        return  $this->encryptionPassword($input_pass)==$pass;
    }
    public function encryptionPassword($password)
    {
        return md5('fsf'.$password.'fgscww');
    }

    /**
     * 修改用户
     */
    public function editData($map,$data){
        // 对data数据进行验证
        if(!$data=$this->create($data)){
            // 验证不通过返回错误
            return false;
        }else{
            // 验证通过
            $result=$this
            ->where(array($map))
            ->save($data);
            return $result;
        }
    }
}